﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace market
{
    public partial class orderAdd : System.Web.UI.Page
    {
        CommonClass cobj = new CommonClass();
        DBClass dbobj = new DBClass();
        OrderClass order = new OrderClass();
        protected void Page_Load(object sender, EventArgs e)
        {
            check_Login();
        }
        public void check_Login()
        {
            if ((Session["AName"] == null))
            {
                Response.Write("<script>alert('对不起！您不是管理员，无权限浏览此页！');location='Login.aspx'</script>");
                Response.End();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strsql = "select count(OrderID) from OrderInfo";
            int ID = Convert.ToInt32(dbobj.ExecScalar(dbobj.GetCommandStr(strsql)))+1;
            string dt = this.txtDate.Value.ToString();
            DateTime.TryParse(dt, out DateTime dateTime);
            //Response.Write("<script>alert('" + dateTime.ToString() + "')</script>");
            float ototal = (float)Convert.ToDouble(this.txtOdtotal.Text.ToString());
            float ffare = (float)Convert.ToDouble(this.txtFrfare.Text.ToString());
            string stype = this.txtShipType.Text.ToString();
            string name = this.txtName.Text.ToString();
            string phone = this.txtPhone.Text.ToString();
            string pcode = this.txtPostCode.Text.ToString();
            string address = this.txtAddress.Text.ToString();
            string email = this.txtEmail.Text.ToString();
            string strAddOrder = "Insert into OrderInfo" +
                "(OrderID, OrderDate, OrderTotal, FreightFare, TotalPrice, ShipType, ReceiverName, ReceiverPhone, ReceiverPostCode, ReceiverAddress, ReceiverEmail) " +
                "values('"+ ID + "','" + dateTime + "','" + ototal + "','" + ffare + "','" + (ototal+ffare) + "','" + stype + "','" + name + "','" + phone + "','" + pcode + "','" + address + "','" + email +"')";
            SqlCommand Cmd = dbobj.GetCommandStr(strAddOrder);
            dbobj.ExecNonQuery(Cmd);
            Response.Write(cobj.MessageBoxPage("添加成功"));
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtDate.Value = "";
            this.txtOdtotal.Text = "";
            this.txtFrfare.Text = "";
            this.txtShipType.Text = "";
            this.txtName.Text = "";
            this.txtPhone.Text = "";
            this.txtPostCode.Text = "";
            this.txtAddress.Text = "";
            this.txtEmail.Text = "";
        }
    }
}